package com.socool.sinofaith.adapter;

import java.util.ArrayList;
import java.util.List;

import com.socool.sinofaith.R;
import com.socool.sinofaith.model.Task;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class CurrentTaskAdapter extends BaseAdapter {

	private List<Task> mdatas = new ArrayList<Task>();
	private LayoutInflater inflater;

	private Context mContext;

	public List<Task> getMdatas() {
		return mdatas;
	}

	public void setMdatas(List<Task> mdatas) {

		this.mdatas = mdatas;
	}

	public void addDatas(List<Task> mdatas) {
		this.mdatas.addAll(mdatas);
		this.notifyDataSetChanged();
	}

	public CurrentTaskAdapter(Context _context) {
		super();
		mContext = _context;
		inflater = LayoutInflater.from(_context);
	}

	@Override
	public int getCount() {
		if (mdatas != null) {
			return mdatas.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {

		ViewHolder mViewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.currenttask_listitem, null);
			mViewHolder = new ViewHolder();
			mViewHolder.taskName = (TextView) convertView
					.findViewById(R.id.taskNameTextView);
			mViewHolder.endTime = (TextView) convertView
					.findViewById(R.id.endTimeTextView);
			mViewHolder.publicButton= (Button) convertView
					.findViewById(R.id.publicButton);
			convertView.setTag(mViewHolder);

		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}
		mViewHolder.taskName.setText(mdatas.get(position).getTaskName());
		mViewHolder.endTime.setText(mdatas.get(position).getEndTM());
		if (mdatas.get(position).getIsPublic().equals("1")) {
			mViewHolder.publicButton.setBackgroundResource(R.drawable.btn_cyan);
			mViewHolder.publicButton.setText(" 公共 ");
		} else {
			mViewHolder.publicButton.setBackgroundResource(R.drawable.btn_blue);
			mViewHolder.publicButton.setText(" 指派 ");
		}
		return convertView;
	}

	public final class ViewHolder {

		public TextView taskName;
		public TextView endTime;
		public Button publicButton;

	}

}
